$(function ()   {
    $.ajax({
        type:"post",
        url:"/OutCount/OutCountDetail",
        data:{},
        dataType:"json",
        success:function(r){
            if (r.data != null){
                console.log(r);
                var t="";
                for (var i=0;i < r.data.length;i++){
                    t += "<tr>\n" +
                        "          <td>"+(i+1)+"</td>\n" +
                        "          <td>"+r.data[i].housename+"</td>\n" +
                        "          <td class='orderid'>"+r.data[i].orderid+"</td>\n" +
                        "          <td>"+r.data[i].goodscomment+"</td>\n" +
                        "          <td>"+r.data[i].totalprice+"</td>\n" +
                        "          <td>"+r.data[i].outcounttime+"</td>\n" +
                        "          <td>"+r.data[i].outcountman+"</td>\n" +
                        "          <td>\n" +
                        "          \t<a href=\"javascript:void(0)\" onclick='toOrderDetailView(this)' class=\"tablelink\">查看详情</a>\n" +
                        "          </td>\n" +
                        "        </tr>"
                }
                $(".tablelist tbody").html(t);
                var pageNum = document.getElementById("pageNum");
                pageNum.innerHTML=r.pageNum
                var totalcomment = document.getElementById("totalcomment");
                totalcomment.innerHTML=r.totalRows;
                totalPage=r.totalPage;
                getpagemodel(totalPage);
            }
        },
        error:function (r) {
            alert("!!!")
        }

    })
})

var totalPage;
//上一页
function shangyiye() {
    var pagenum = document.getElementById("pageNum");
    var n=pagenum.innerHTML
    if (n>1){
        n--;
        $.ajax({
            type:"post",
            url:"/OutCount/OutCountDetail",
            data:{pagenum:n},
            dataType:"json",
            success:function(r){
                if (r.data != null){
                    var t="";
                    for (var i=0;i < r.data.length;i++){
                        t += "<tr>\n" +
                            "          <td>"+(i+1)+"</td>\n" +
                            "          <td>"+r.data[i].housename+"</td>\n" +
                            "          <td class='orderid'>"+r.data[i].orderid+"</td>\n" +
                            "          <td>"+r.data[i].goodscomment+"</td>\n" +
                            "          <td>"+r.data[i].totalprice+"</td>\n" +
                            "          <td>"+r.data[i].outcounttime+"</td>\n" +
                            "          <td>"+r.data[i].outcountman+"</td>\n" +
                            "          <td>\n" +
                            "          \t<a href=\"javascript:void(0)\" onclick='toOrderDetailView(this)' class=\"tablelink\">查看详情</a>\n" +
                            "          </td>\n" +
                            "        </tr>"
                    }
                    $(".tablelist tbody").html(t);
                    var pageNum = document.getElementById("pageNum");
                    pageNum.innerHTML=r.pageNum;
                    var totalcomment = document.getElementById("totalcomment");
                    totalcomment.innerHTML=r.totalRows;
                    totalPage=r.totalPage;
                    getpagemodel(totalPage);
                }
            },
            error:function (r) {
                alert("!!!")
            }

        })
    }else{
        alert("已经是第一页了")
    }
}
//下一页
function xiayiye() {
    var pagenum = document.getElementById("pageNum");
    var n=pagenum.innerHTML
    if (n<totalPage){
        n++;
        $.ajax({
            type:"post",
            url:"/OutCount/OutCountDetail",
            data:{pagenum:n},
            dataType:"json",
            success:function(r){
                if (r.data != null){
                    var t="";
                    for (var i=0;i < r.data.length;i++){
                        t += "<tr>\n" +
                            "          <td>"+(i+1)+"</td>\n" +
                            "          <td>"+r.data[i].housename+"</td>\n" +
                            "          <td class='orderid'>"+r.data[i].orderid+"</td>\n" +
                            "          <td>"+r.data[i].goodscomment+"</td>\n" +
                            "          <td>"+r.data[i].totalprice+"</td>\n" +
                            "          <td>"+r.data[i].outcounttime+"</td>\n" +
                            "          <td>"+r.data[i].outcountman+"</td>\n" +
                            "          <td>\n" +
                            "          \t<a href=\"javascript:void(0)\" onclick='toOrderDetailView(this)' class=\"tablelink\">查看详情</a>\n" +
                            "          </td>\n" +
                            "        </tr>"
                    }
                    $(".tablelist tbody").html(t);
                    var pageNum = document.getElementById("pageNum");
                    pageNum.innerHTML=r.pageNum;
                    var totalcomment = document.getElementById("totalcomment");
                    totalcomment.innerHTML=r.totalRows;
                    totalPage=r.totalPage;
                    getpagemodel(totalPage);
                }
            },
            error:function (r) {
                alert("!!!")
            }

        })
    }else{
        alert("已经是最后一页了")
    }
}
//渲染页数
function getpagemodel(n) {
    var t="<li class=\"paginItem\"><a href=\"javascript:;\" onclick=\"shangyiye()\"><span class=\"pagepre\"></span></a></li>\n";
    for(var i=1;i<=n;i++){
        t+="<li class=\"paginItem\"><a href=\"javascript:;\" onclick='choiseModel(this)'>"+i+"</a></li>\n";
    }
    t+="<li class=\"paginItem\"><a href=\"javascript:;\" onclick=\"xiayiye()\"><span class=\"pagenxt\"></span></a></li>";
    $(".paginList").html(t);
}
//选择页码去到分页
function choiseModel(n) {
    var pagenum = $(n).html();
    $.ajax({
        type:"post",
        url:"/OutCount/OutCountDetail",
        data:{pagenum:pagenum},
        dataType:"json",
        success:function(r){
            if (r.data != null){
                var t="";
                for (var i=0;i < r.data.length;i++){
                    t += "<tr>\n" +
                        "          <td>"+(i+1)+"</td>\n" +
                        "          <td>"+r.data[i].housename+"</td>\n" +
                        "          <td class='orderid'>"+r.data[i].orderid+"</td>\n" +
                        "          <td>"+r.data[i].goodscomment+"</td>\n" +
                        "          <td>"+r.data[i].totalprice+"</td>\n" +
                        "          <td>"+r.data[i].outcounttime+"</td>\n" +
                        "          <td>"+r.data[i].outcountman+"</td>\n" +
                        "          <td>\n" +
                        "          \t<a href=\"javascript:void(0)\" onclick='toOrderDetailView(this)' class=\"tablelink\">查看详情</a>\n" +
                        "          </td>\n" +
                        "        </tr>"
                }
                $(".tablelist tbody").html(t);
                var pageNum = document.getElementById("pageNum");
                pageNum.innerHTML=r.pageNum;
                var totalcomment = document.getElementById("totalcomment");
                totalcomment.innerHTML=r.totalRows;
                totalPage=r.totalPage;
                getpagemodel(totalPage);
            }
        },
        error:function (r) {
            alert("!!!")
        }
    })
}

function toOrderDetailView(n){
    var orderid = $(n).parent().parent().children("td[class='orderid']").html();
    $.ajax({
        type:"post",
        url:"/OutCount/toCommentDeliveryView",
        data:{orderid:orderid},
        dataType:"json",
        success:function(r){
            location.href="/storage/delivery/deliveryView.html";
        },
        error:function (r) {
            alert("!!!")
        }
    })
}